# -*- coding: utf-8 -*-
"""
Created on Tue Apr 16 13:15:34 2024
利用数据框中的iloc属性可以实现下标值或者逻辑值定位索引，并进行切片操作
@author: 29865
"""

import pandas as pd
import numpy as np
data = {'a': [2, 2, np.nan, 5, 6],
        'b': ['kl', 'kl', 'kl', np.nan, 'kl'],
        'c': [4, 6, 5, np.nan, 6],
        'd': [7, 9, np.nan, 9, 8]}
df = pd.DataFrame(data)

# 使用一个固定的值填充所有 NaN
df_filled = df.fillna(0)

c3 = df_filled.iloc[1:3, 2]
c4 = df_filled.iloc[1:3, 0:2]
c5 = df_filled.iloc[1:3, :]
c6 = df_filled.iloc[[0, 2, 3], [1, 2]]
TF = [True, False, False, True, True]
c7 = df_filled.iloc[TF, [1]]
